import QQMapWX from '../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js';
var qqmapsdk ;
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    addressMenuIsShow: false,
    consigneeName: "",
    phone: "",
    detailedAddress: "",
    defaults: false,        // 默认
  },
  consigneeNameInput: function(e) { //获取收货人
    this.setData({
      consigneeName: e.detail.value
    })
  },
  phoneInput: function(e) { //获取手机号
    this.setData({
      phone: e.detail.value
    })
  },
  consigneeRegionInput: function(e) { //获取所在地址
 
    this.setData({
      consigneeRegion: e.detail.value
    })
  },
  detailedAddressInput: function(e) { //获取详细地址
    this.setData({
      detailedAddress: e.detail.value
    })
  },
  save: function() {
    var consigneeName = this.data.consigneeName;
    var phone = this.data.phone;
    var consigneeRegion = this.data.consigneeRegion;
    var detailedAddress = this.data.detailedAddress
    if (consigneeName == "") {
      wx: wx.showToast({
        title: '请输入姓名',
        image: "/static/icon/notice.png"
      })
      return false
    }
    else if (phone == "") {
      wx: wx.showToast({
        title: '请输入手机号码',
        image: "/static/icon/notice.png"
      })
      return false
    }
    else if (consigneeRegion == "") {
      wx: wx.showToast({
        title: '请选择地址',
        image: "/static/icon/notice.png"
      })
      return false
    }
    else if (detailedAddress == "") {
      wx: wx.showToast({
        title: '请输入门牌号',
        image: "/static/icon/notice.png"
      })
      return false
    }
    else {
      wx.navigateTo({
        url: '/pages/addr/index',
      })
    }
  },
getAddress(e) {
    //使用chooseLocation选择位置
    var that = this
    wx.chooseLocation({
      success:function(res){
        that.setData({locationpath:res.address});
      },
    })
    },
  //key: 'UXGBZ-LIVL6-7KWSN-E7G4N-7VHUO-PNBQV'
  /**
   * 生命周期函数--监听页面加载
   */
 // onLoad: function(options) {
/**
 * wx.getSetting({
      success: (res) => {
        // res.authSetting['scope.userLocation'] == undefined    表示 初始化进入该页面
        // res.authSetting['scope.userLocation'] == false    表示 非初始化进入该页面,且未授权
        // res.authSetting['scope.userLocation'] == true    表示 地理位置授权
        if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
          wx.showModal({
            title: '请求授权当前位置',
            content: '需要获取您的地理位置，请确认授权',
            success: function (res) {
              if (res.cancel) {
                wx.showToast({
                  title: '拒绝授权',
                  icon: 'none',
                  duration: 1000
                })
              } else if (res.confirm) {
                wx.openSetting({
                  success: function (dataAu) {
                    if (dataAu.authSetting["scope.userLocation"] == true) {
                      wx.showToast({
                        title: '授权成功',
                        icon: 'success',
                        duration: 1000
                      })
                      //再次授权，调用wx.getLocation的API
                      this.getAddress();
                    } else {
                      wx.showToast({
                        title: '授权失败',
                        icon: 'none',
                        duration: 1000
                      })
                    }
                  }
                })
              }
            }
          })
        } else {
          //调用wx.getLocation的API
          this.getAddress();
        }
      }
    })
  },
 //获取定位信息
 getAddress(){
  // 实例化腾讯地图API核心类
  qqmapsdk = new QQMapWX({
    key: 'UXGBZ-LIVL6-7KWSN-E7G4N-7VHUO-PNBQV'
  });
  var that = this;
  //获取当前位置
  wx.getLocation({
    type: 'wgs84',
    success: function (res) {
      var lat = res.latitude;
      var lon = res.longitude;
      //根据坐标获取当前位置名称，腾讯地图逆地址解析
      qqmapsdk.reverseGeocoder({
        location: { latitude: lat, longitude: lon },
        success: function (res) {
          var address = res.result.address;
          that.setData({
            latitude: lat,
            longitude: lon,
            markers: [{
              id: '1',
              width: 22,
              height: 32,
              latitude: lat,
              longitude: lon,
              callout: {
                content: address,
                color: "#393939",
                textAlign: 'center',
                fontSize: 13,
                borderRadius: 20,
                bgColor: "#ffffff",
                padding: 10,
                display: "ALWAYS"
              },
            }]
          })
        }
      });
    }
  });
  */
//},
onLoad: function (options) {
  var that = this;
  that.setData({
    navH: app.globalData.navHeight
  })
},
navBack: function () {
  wx.navigateBack({
    delta: 1
  })
},
navHome: function () {
  wx.reLaunch({
    url: '/pages/index/index'
  })
},
  /**
   * 是否选择默认
   */
  chooseDefault: function() {
    this.setData({
      defaults: !this.data.defaults
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
 
  }
})